Translation API Documentation
Endpoint
- Method: POST
- Path:
https://api.kadal.ai/translation/api/v1/text - Summary: Translates text into a selected target language using AI models.
Description
This endpoint translates text into a specified target language, such as Arabic, Chinese, French, Hindi, Spanish, and more. The AI model (e.g., gpt-4o or gpt-4o-mini) can be selected to balance translation quality and speed.
Request
- Content-Type: multipart/form-data
Payload
| Parameter | Description | Data Type | Allowed Values | Required |
|---|---|---|---|---|
| source_text | Text to translate | String | yes | |
| model | AI model used for translation | String | gpt-4o, gpt-4o-mini | yes |
| target_language | Target language for translation | String | Arabic, Chinese, Dari, English, French, Hindi, Kannada, Korean, Pashto, Spanish, Turkish | yes |
Response
{
"status_code": 200,
"message": "Success: Translation generated successfully.",
"translation": "Translated text here"
}
Error Responses
| Status Code | Message | Description |
|---|---|---|
| 404 | Not found | Model not found - Invalid model |
Usage
import requests
# Define the API endpoint and the payload
url = "https://api.kadal.ai/translation/api/v1/text"
token = "your_token_here"
headers = {
"accept": "application/json",
"Authorization": f"Bearer {token}",
"Content-Type": "application/x-www-form-urlencoded"
}
data = {
"source_text": "Hello, How are you?",
"target_language": "Hindi",
"model": "gpt-4o-mini"
}
# Make the POST request
response = requests.post(url, headers=headers, data=data)
# Print the response
if response.status_code == 200:
print("Response Data:", response.json())
else:
print("Failed to call the API. Status Code:", response.status_code)
print("Response Text:", response.text)